package com.sky.service.impl;

import com.sky.constant.RedisConstant;
import com.sky.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author wuJiaWei
 * @version 1.0
 */
@Service
@Slf4j
public class ShopServiceImpl implements ShopService {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @Override
    public void startOrStop(Integer status) {
        redisTemplate.opsForValue().set(RedisConstant.SHOP_STATUS, status);
    }

    @Override
    public Integer status() {
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get(RedisConstant.SHOP_STATUS);
        log.info("店铺状态：{}", Objects.requireNonNull(shopStatus) == 1 ? "营业中" : "打烊了");
        return shopStatus;
    }
}
